package cn.songhaiqing.walle.help;

import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;

import cn.songhaiqing.walle.bean.Alarm;

public class ParserHelper {
    public static byte[] getgsensor(boolean isVibration) {
        byte[] value = new byte[20];
        value[0] = 83;
        value[1] = 2;
        if (isVibration) {
            value[2] = 1;
        } else {
            value[2] = 0;
        }
        return value;
    }

    public static byte[] getBooleanArray(byte b) {
        byte[] array = new byte[8];
        for (int i = 7; i >= 0; i--) {
            array[i] = (byte) (b & 1);
            b = (byte) (b >> 1);
        }
        return array;
    }

    public static String byteToBinaryString(int b) {
        int size;
        String binary = Integer.toBinaryString(b);
        if (binary != null && (size = binary.length()) < 8) {
            for (int i = 0; i < 8 - size; i++) {
                binary = "0" + binary;
            }
        }
        return binary;
    }

    public static String getRepeatDateBinary(int mon, int tue, int wed, int thu, int fri, int sat, int sun) {
        StringBuffer sb = new StringBuffer();
        sb.append("0");
        if (sat == 0) {
            sb.append(1);
        } else {
            sb.append(0);
        }
        if (fri == 0) {
            sb.append(1);
        } else {
            sb.append(0);
        }
        if (thu == 0) {
            sb.append(1);
        } else {
            sb.append(0);
        }
        if (wed == 0) {
            sb.append(1);
        } else {
            sb.append(0);
        }
        if (tue == 0) {
            sb.append(1);
        } else {
            sb.append(0);
        }
        if (mon == 0) {
            sb.append(1);
        } else {
            sb.append(0);
        }
        if (sun == 0) {
            sb.append(1);
        } else {
            sb.append(0);
        }
        return sb.toString();
    }

    public static int getRepeatDate(Alarm alarm) {
        if (alarm != null) {
            return Integer.parseInt(getRepeatDateBinary(alarm.getMonday(), alarm.getTuesday(), alarm.getWednesday(), alarm.getThursday(), alarm.getFriday(), alarm.getSaturday(), alarm.getSunday()), 2);
        }
        return 0;
    }

    public static String phoneNumberFilter(String number) {
        if (number == null || number.equals("")) {
            return null;
        }
        StringBuffer sb = new StringBuffer();
        char[] num = number.toCharArray();
        for (char c : num) {
            if (Character.isDigit(c)) {
                sb.append(c);
            }
        }
        if (sb.length() < 2 || !sb.substring(0, 2).equalsIgnoreCase("86")) {
            return sb.toString();
        }
        return sb.toString().substring(2);
    }

    public static byte getASCIIValue(int number) {
        switch (number) {
            case 1:
                return 49;
            case 2:
                return 50;
            case 3:
                return 51;
            case 4:
                return 52;
            case 5:
                return 53;
            case 6:
                return 54;
            case 7:
                return 55;
            case 8:
                return 56;
            case 9:
                return 57;
            default:
                return 48;
        }
    }

    public static String getNameByNumber(Context context, String address) {
        Cursor cursor = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, new String[]{"display_name", "data1"}, "data1='" + address + "'", null, null);
        if (cursor == null) {
            return null;
        }
        System.out.println("cursor getCount = " + cursor.getCount());
        if (cursor.getCount() == 0) {
            return null;
        }
        cursor.moveToPosition(0);
        String name = cursor.getString(cursor.getColumnIndex("display_name"));
        System.out.println("name = " + name);
        return name;
    }

    public static int getByteValue(byte title) {
        if (title < 0) {
            return title + 256;
        }
        return title;
    }

    /* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: byte[] */
    /* JADX DEBUG: Multi-variable search result rejected for r0v0, resolved type: int[] */
    /* JADX DEBUG: Multi-variable search result rejected for r2v2, resolved type: byte */
    /* JADX DEBUG: Multi-variable search result rejected for r2v3, resolved type: byte */
    /* JADX DEBUG: Multi-variable search result rejected for r2v5, resolved type: byte */
    /* JADX WARN: Multi-variable type inference failed */
    public static int[] arraysByte2Int(byte[] value) {
        int[] dat = new int[value.length];
        for (int i = 0; i < value.length; i++) {
            if (value[i] >= 0) {
                dat[i] = value[i];
            } else {
                dat[i] = value[i] + 256;
            }
        }
        return dat;
    }
}
